package com.yubest.security.filter;

import cn.hutool.extra.servlet.ServletUtil;
import cn.hutool.json.JSONUtil;
import com.yubest.security.bean.Response;
import com.yubest.security.consts.Consts;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.AuthenticationEntryPoint;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class MyAuthenticationEntryPoint implements AuthenticationEntryPoint {

    @Override
    public void commence(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, AuthenticationException e) throws IOException, ServletException {
        Response<Void> data = Response.error(Consts.NOT_PERMIT_CODE, "请先登陆");
        ServletUtil.write(httpServletResponse, JSONUtil.toJsonStr(data), "application/json;charset=utf-8");
    }
}
